<?php

 $xmlstring = <<<XML
<?xml version = "1.0" encoding="UTF-8" standalone="yes"?>
<document>
  <animal>koala</animal>
  <animal>kangaroo</animal>
  <animal>wombat</animal>
  <animal>wallaby</animal>
  <animal>emu</animal>
  <animal>kiwi</animal>
  <animal>kookaburra</animal>
  <animal>platypus</animal>
  <animal>funnel web</animal>
</document>
XML;

//try {
//    /*** a new simpleXML iterator object ***/
//    $sxi =  new SimpleXMLIterator($xmlstring);
//
//    /*** add a child ***/
//    $sxi->addChild('animal', 'Tiger');
//
//    /*** a new simpleXML iterator object ***/
//    $new = new SimpleXmlIterator($sxi->saveXML());
//
//    /*** iterate over the new tree ***/
//    foreach($new as $val)
//        {
//        echo $val.'<br />';
//        }
//    }
//catch(Exception $e)
//    {
//    echo $e->getMessage();
//    }
    
    
    try {
    /*** a new simpleXML iterator object ***/
    $sxi =  new SimpleXMLIterator($xmlstring);

    /*** add an attribute with a namespace ***/
    $sxi->addAttribute('id:att1', 'good things', 'urn::test-foo');

    /*** add an attribute without a  namespace ***/
    $sxi->addAttribute('att2', 'no-ns');

    echo htmlentities($sxi->saveXML());
    }
catch(Exception $e)
    {
    echo $e->getMessage();
    }